package com.edu.servlet;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.edu.bean.Book;
import com.edu.service.BookService;
import com.edu.service.UserService;
import com.edu.service.impl.BookServiceImpl;
import com.edu.service.impl.UserServiceImpl;


@WebServlet("/updateBook.do")
public class UpdateBookServlet extends HttpServlet {
	
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		Object u = request.getSession().getAttribute("loginUser");
			if(u == null){
				response.sendRedirect("login.jsp");
				return;
		}
	
		BookService bs = new BookServiceImpl();
		request.setCharacterEncoding("utf-8");
		String bookName = request.getParameter("bookName");
		String bookType = request.getParameter("bookType");
		String bookWriter = request.getParameter("bookWriter");
		String bookPrice = request.getParameter("bookPrice");
		String bookNum = request.getParameter("bookNum");
		String bookId = request.getParameter("bookId");
		
		int id = Integer.parseInt(bookId);
		double price = Double.parseDouble(bookPrice);
		int num = Integer.parseInt(bookNum);
		Book book = new Book(id,bookName,price,bookWriter,num,bookType);
		bs.updateBook(book);
		response.sendRedirect("book.jsp");
	}

}
